#ifndef __SERVER_CLIENT_MANAGER__
#define __SERVER_CLIENT_MANAGER__

#include <list>
#include <windows.h>
#include <cassert>

#include "..\Common\CommonNetwork.h"



const int UDP_NOT_READY = 0;

class client_manager {
public:
	struct client_save_structure {	// clinet info structure. 
		unsigned int	ClientCode;
		network*		ServiceNetwork;
		network*		BroadcastNetwork;
		int				UdpPort;		
		unsigned int	ServiceThreadNumber;

		unsigned int	UdpConnectCount;
		unsigned int	LastUdpRecvCount;
		unsigned int	LastUdpRecvCountUpdate;
		unsigned int	CurrentUdpRecvCount;
		
	};

	typedef std::list<client_save_structure>	clinet_info_list;		

private:
	clinet_info_list			m_ClientInfoList;
	clinet_info_list::iterator	m_Repeator;
	CRITICAL_SECTION			m_CriticalSection;
	bool						m_bRepeating;
	bool						m_bLock;	

public:
	client_manager(void);
	~client_manager(void);

	// Repeat Methods.
	void					StartRepeat(void);
	void					EndRepeat(void);
	void					NextRepeat(void);
	client_save_structure*	Repeat(void);

	int	GetClientCount(void);
	bool NewClient(network* ServiceNetwork, network* BroadcasterNetwork, unsigned int ThreadNumber);
	bool DeleteClient(unsigned int ClientCode);
	
	void Lock(void);
	client_save_structure* SearchClient(network* PtrNetwork);	
	client_save_structure* SearchClient(unsigned int ClientCode);
	void UnLock(void);

	int GenerateClientCode(void);
};

#endif